/* 1051. 高度检查器 */
/**
 * @param {number[]} heights
 * @return {number}
 */
var heightChecker = function (heights) {
	const temp = [...heights].sort((a, b) => a - b)
	return temp.filter((item, index) => item !== heights[index]).length
}
/* 
    计数排序 
    小于100
*/
var heightChecker = function (heights) {
	const max = Math.max(...heights)
	const cnt = new Array(max + 1).fill(0)
	for (const height of heights) {
		++cnt[height]
	}
	let idx = 0,
		ans = 0
	for (let i = 1; i <= max; i++) {
		for (let j = 1; j <= cnt[i]; ++j) {
			if (heights[idx] !== i) {
				++ans
			}
			++idx
		}
	}
	return ans
}
const ans = heightChecker([1, 1, 4, 2])
console.log('heightChecker :>>', ans)
